﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.EnterpriseCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.DTO.Output;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.EnterpriseHandler
{
    public class EnterpriselistCommandHandler : IRequestHandler<EnterpriseListCommand, Results<PageOutput<Enterprise>>>
    {

        private readonly IEnterpriseService enterpriseService;

        public EnterpriselistCommandHandler(IEnterpriseService enterpriseService)
        {
            this.enterpriseService = enterpriseService;
        
        }
        /// <summary>
        /// 企业显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<PageOutput<Enterprise>>> Handle(EnterpriseListCommand request, CancellationToken cancellationToken)
        {

            //var list = mapper.Map<List<Enterprise>>(enterpriseService.GetEnterprises()).ToList();

            //return Results<List<Enterprise>>.DataResult(list);

            return Results<PageOutput<Enterprise>>.DataResult(await enterpriseService.GetEnterprises(request.EnterpriseName,request.pageIndex,request.pageSize));
        }
    }
}
